
package edu.uoc.tdp.pac4.servidor;

/**
 *
 * @author pguerreroj
 */

import edu.uoc.tdp.pac4.i18n.TDSLanguageUtils;
import edu.uoc.tdp.pac4.cliente.Principal;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;





public class PrincipalServer extends JFrame{
  
    JDesktopPane escritorio;
    
    public PrincipalServer() {
        seleccionDeIdioma();
        initComponents();
    }
    
    private void seleccionDeIdioma() {
        Locale localLocale = new Locale("es", "ES");
        TDSLanguageUtils.setDefaultLanguage("i18n/messages");
    }
    
    public void initComponents(){
        setTitle(TDSLanguageUtils.getMessage("Server.title"));
        escritorio=new JDesktopPane();
        add(escritorio);
        JMenuBar barra=new JMenuBar();
        JMenu inicio=new JMenu(TDSLanguageUtils.getMessage("Principal.JmenuGestor"));
        JMenuItem inicio1=new JMenuItem(TDSLanguageUtils.getMessage("Principal.JmenuConectar"));
        inicio1.addActionListener(new ActionListener() {
          
            @Override
            public void actionPerformed(ActionEvent arg0) {
               // Servidor2 conn = new Servidor2();
                EjemploServidor conn = new EjemploServidor();
                conn.setBounds(10,0,500,550);
                escritorio.add(conn);  
                conn.show();
            }
        });
        JMenuItem inicio2=new JMenuItem(TDSLanguageUtils.getMessage("Principal.JmenuSalir"));
        inicio2.addActionListener(new ActionListener() {
          
            @Override
            public void actionPerformed(ActionEvent arg0) {
                 int respuesta = JOptionPane.showConfirmDialog(null,TDSLanguageUtils.getMessage("Principal.Salir"),"Alerta",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
                 if (respuesta == 0) {  
                     System.exit(0);
                 }  
            }
        });
       
        inicio.add(inicio1);
        inicio.add(inicio2);
        barra.add(inicio);
        setJMenuBar(barra);
      
    }
    
    public static void main(String args[]) {
        
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                PrincipalServer p = new PrincipalServer();
                p.setSize(550,600);
                p.setVisible(true);
                p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                
            }
        });
    }
}